<?php

/**
 * a+b+c = 1000 a^2 + b^2 = c^2  求a  b c 的值
 */
function gu($endNum,$sum){
    for($a=0;$a<$endNum;$a++){//1001
        for($b=0;$b<$endNum;$b++){
            $c = $sum - $a -$b;
            if($a**2 + $b**2 == $c**2){//1000
                print_r("a,b,c: $a, $b, $c ".PHP_EOL);
            }
        }
    }
}

/**
 * 这段代码的时间复杂度
 * T(n) = n * n * (1+ max(1,0))
 *      = n^2 * 2      忽略常数项
 *      = O(n^2)
 */
$endNum = 1001;
$sum = 1000;
$starttime = explode(' ',microtime());
gu($endNum,$sum);//笨方法
$endtime = explode(' ',microtime());//程序运行时间
$thistime = $endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]);
$thistime = round($thistime,3);
echo "本代码片段执行耗时：".$thistime." 秒。".time();

